import {observable, action} from "mobx";
import {Form} from "weaver-mobile-page";
import * as API from "../../api";

export default class TaskFormStore {
    @observable isLoading = true;
    @observable taskid;
    @observable viewtype;
    @observable taskForm = new Form.Store();
    @action
    init = (taskid, viewtype) => {
        this.taskid = taskid;
        this.viewtype = viewtype;
        this.getTaskForm(taskid, viewtype);
    }
    @action
    getTaskForm = (taskid, viewtype) => {
        this.isLoading = true;
        const params = {
            "taskid": taskid,
            "viewtype": viewtype
        };
        this.taskForm = new Form.Store();
        API.getTaskForm(params).then(action(res => {
            this.isLoading = false;
            this.taskForm.initForm(res.fieldinfo, "/taskForm");
        }))
    }

    @action
    getParams = (form) => {
        return form.formParams;
    };

    @action
    updateField = (form, key, value) => {
        form.updateField(key, value);
    };
    @action
    clearForm = (form) => {
        form.resetFields();
    };
}
